
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<title>YUI Library Examples: Overlay: IO Plugin</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    	<link rel="stylesheet" type="text/css" href="../../assets/yui.css" >

<style>
    /*Supplemental CSS for the YUI distribution*/
    #custom-doc { width: 95%; min-width: 950px; }
    #pagetitle {background-image: url(../../assets/bg_hd.gif);}
/*    #pagetitle h1 {background-image: url(../../assets/title_h_bg.gif);}*/
</style>

<link rel="stylesheet" type="text/css" href="../../assets/dpSyntaxHighlighter.css">
<link type="text/css" rel="stylesheet" href="../../build/cssfonts/fonts-min.css" />
<script type="text/javascript" src="../../build/yui/yui-min.js"></script>
<style type="text/css">
    .yui-overlay-content {
        padding:5px;
        background-color:#ccc;
        border:1px solid #000;
    }

    .yui-overlay .yui-widget-hd, 
    .yui-overlay .yui-widget-bd, 
    .yui-overlay .yui-widget-ft {
        background-color:#eee;
        padding:2px;
        border:1px solid #999;
        text-align:left;
    }

    .yui-overlay .yui-widget-bd {
        background-color:#fff;
        text-align:center;
        vertical-align:middle;
    }

    .yui-overlay .yui-widget-bd .yui-feed-data {
        text-align:left;
    }

    .yui-overlay .yui-feed-selector .yui-prompt {
        font-weight:bold;
    }

</style>
</head>
<body id="yahoo-com" class=" yui-skin-sam">
<div id="custom-doc" class="yui-t2">
<div id="hd">
	<div id="ygunav">
		<p>
            <em>
                <a href="http://developer.yahoo.com/yui/3/">YUI 3.x Home</a> <i> - </i>	
            </em>
		</p>
		<form action="http://search.yahoo.com/search" id="sitesearchform">
            <input name="vs" type="hidden" value="developer.yahoo.com">
            <input name="vs" type="hidden" value="yuiblog.com">
		    <div id="sitesearch">
		    	<label for="searchinput">Site Search (YDN &amp; YUIBlog): </label>
			    <input type="text" id="searchinput" name="p">
			    <input type="submit" value="Search" id="searchsubmit" class="ygbt">
		    </div>
		</form>
    </div>
	<div id="ygma"><a href="../../"><img src="../../assets/logo.gif"  border="0" width="200" height="93"></a></div>
	<div id="pagetitle"><h1>YUI Library Examples: Overlay: IO Plugin</h1></div>
</div>
<div id="bd">

	<div id="bar-note"><p><strong>Note:</strong> This is YUI 3.x. Looking for <a href="http://developer.yahoo.com/yui/">YUI 2.x</a>?</p></div>

	<div id="yui-main">
		<div class="yui-b">
		  <div class="yui-ge">
			  <div class="yui-u first example" id="main">

	<h2>Overlay: IO Plugin</h2>

	<div id="example" class="promo">
	<p>
	<p>This example shows how you can use Widget's plugin infrastructure to add additional features to an existing widget.</p>
<p>We create an IO plugin class for <code>Overlay</code> called <code>StdModIOPlugin</code>. The plugin adds IO capabilities to the Overlay, bound to one of its standard module sections <em>(header, body or footer)</em>.</p>
	</p>	

	<div class="module example-container ">
			<div class="hd exampleHd">
			<p class="newWindowButton yui-skin-sam">
                <a href="overlay-io-plugin_clean.html" target="_blank">View example in new window.</a>
            </p>
		</div>		<div id="example-canvas" class="bd">

		
	<!--BEGIN SOURCE CODE FOR EXAMPLE =============================== -->
	
	<button type="button" id="show">Show Overlay</button>
<button type="button" id="hide">Hide Overlay</button>

<script type="text/javascript">
YUI({base:"../../build/", timeout: 10000}).use("overlay", "substitute", "io", "json", "plugin", function(Y) {

    var StdMod = Y.WidgetStdMod;

    /* Standard Module IO Plugin Constructor */
    function StdModIOPlugin(config) {
        StdModIOPlugin.superclass.constructor.apply(this, arguments);
    }

    /* 
     * The namespace for the plugin. This will be the property on the widget, which will 
     * reference the plugin instance, when it's plugged in
     */
    StdModIOPlugin.NS = "io";

    /*
     * The NAME of the StdModIOPlugin class. Used to prefix events generated
     * by the plugin class.
     */
    StdModIOPlugin.NAME = "stdModIOPlugin";

    /*
     * The default set of attributes for the StdModIOPlugin class.
     */
    StdModIOPlugin.ATTRS = {

        /*
         * The uri to use for the io request
         */
        uri : {
            value:null
        },

        /*
         * The io configuration object, to pass to io when intiating a transaction
         */
        cfg : {
            value:null
        },

        /*
         * The default formatter to use when formatting response data. The default
         * implementation simply passes back the response data passed in. 
         */
        formatter : {
            valueFn: function() {
                return this._defFormatter;
            }
        },

        /*
         * The Standard Module section to which the io plugin instance is bound.
         * Response data will be used to populate this section, after passing through
         * the configured formatter.
         */
        section: {
            value:StdMod.BODY,
            validator: function(val) {
                return (!val || val == StdMod.BODY || val == StdMod.HEADER || val == StdMod.FOOTER);
            }
        },

        /*
         * The default loading indicator to use, when an io transaction is in progress.
         */
        loading: {
            value: '<img class="yui-loading" width="32px" height="32px" src="assets/img/ajax-loader.gif">'
        }
    };

    /* Extend the base plugin class */
    Y.extend(StdModIOPlugin, Y.Plugin.Base, {

        /*
         * Initialization code. Called when the 
         * plugin is instantiated (whenever it's 
         * plugged into the host)
         */
        initializer: function(config) {
            Y.io.transport({
                id:'flash',
                yid: Y.id,
                src:'../../build/io/io.swf?stamp=' + (new Date()).getTime()
            });
        },

        /*
         * Destruction code. Terminates the activeIO transaction if it exists
         */
        destructor : function() {
            if (this._activeIO) {
                Y.io.abort(this._activeIO);
                this._activeIO = null;
            }
        },

        /*
         * IO Plugin specific method, use to initiate a new io request using the current
         * io configuration settings.
         */
        refresh : function() {
            section = this.get("section");

            if (section && !this._activeIO) {
                var uri = this.get("uri");

                if (uri) {

                    cfg = this.get("cfg") || {};
                    cfg.on = cfg.on || {};

                    cfg.on.start = cfg.on.start || Y.bind(this._defStartHandler, this);
                    cfg.on.complete = cfg.on.complete || Y.bind(this._defCompleteHandler, this);
    
                    cfg.on.success = cfg.on.success || Y.bind(this._defSuccessHandler, this);
                    cfg.on.failure = cfg.on.failure || Y.bind(this._defFailureHandler, this);

                    cfg.method = cfg.method;  // io defaults to "GET" if not defined

                    Y.io(uri, cfg);
                }
            }
        },

        /*
         * The default io transaction success handler
         */
        _defSuccessHandler : function(id, o) {
            var response = o.responseXML || o.responseText;
            var section = this.get("section");
            var formatter = this.get("formatter");

            this.get("host").setStdModContent(section, formatter(response));
        },

        /*
         * The default io transaction failure handler
         */
        _defFailureHandler : function(id, o) {
            this.get("host").setStdModContent(this.get("section"), "Failed to retrieve content");
        },

        /*
         * The default io transaction start handler
         */
        _defStartHandler : function(id, o) {
            this._activeIO = o;
            this.get("host").setStdModContent(this.get("section"), this.get("loading"));
        },

        /*
         * The default io transaction complete handler
         */
        _defCompleteHandler : function(id, o) {
            this._activeIO = null;
        },

        /*
         * The default response formatter
         */
        _defFormatter : function(val) {
            return val
        }
    });

    /* The Pipes feed URIs to be used to dispatch io transactions */
    var pipes = {

        // uri data
        baseUri : 'http:/'+'/pipes.yahooapis.com/pipes/pipe.run?_id=6b7b2c6a32f5a12e7259c36967052387&_render=json&url=http:/'+'/',
        feeds : {
            ynews : {
                title: 'Yahoo! US News',
                uri: 'rss.news.yahoo.com/rss/us'
            },
            yui : {
                title: 'YUI Blog',
                uri: 'feeds.yuiblog.com/YahooUserInterfaceBlog'
            },
            slashdot : {
                title: 'Slashdot',
                uri: 'rss.slashdot.org/Slashdot/slashdot'
            },
            ajaxian: {
                title: 'Ajaxian',
                uri: 'feeds.feedburner.com/ajaxian'
            },
            daringfireball: {
                title: 'Daring Fireball',
                uri: 'daringfireball.net/index.xml'
            },
            wiredtech: {
                title: 'Wire: Tech Biz',
                uri: 'www.wired.com/rss/techbiz.xml'
            },
            techcrunch: {
                title: 'TechCrunch',
                uri: 'feedproxy.google.com/Techcrunch'
            }
        },

        // The default formatter, responsible for converting the JSON responses recieved,
        // into HTML, using JSON for the parsing step, and substitute for some basic templating functionality
        formatter : function (val) {
            var formatted = "Error parsing feed data";
            try {
                var json = Y.JSON.parse(val);
                if (json && json.count) {
                    var html = ['<ul class="yui-feed-data">'];
                    var linkTemplate = '<li><a href="{link}" target="_blank">{title}</a></li>';
    
                    Y.each(json.value.items, function(v, i) {
                        if (i < 10) {
                            html.push(Y.substitute(linkTemplate, v));
                        }
                    });
                    html.push("</ul>");
                    formatted = html.join("");
                } else {
                    formatted = "No Data Available";
                }
            } catch(e) {
                formatted = "Error parsing feed data";
            }
            return formatted;
        }
    };

    /* Helper function, to generate the select dropdown markup from the pipes feed data */
    function generateHeaderMarkup() {
        var optTemplate = '<option value="{id}">{title}</option>',
            html = ['<select id="feedSelector" class="yui-feed-selector"><option value="-1" class="yui-prompt">Select a Feed...</option>'];

        Y.Object.each(pipes.feeds, function(v, k, o) {
            html.push(Y.substitute(optTemplate, {id:k, title:v.title}));
        });
        html.push('</select>');

        return html.join("");
    }

    /* Create a new Overlay instance, with content generated from script */
    var overlay = new Y.Overlay({
        width:"40em",
        visible:false,
        align: {
            node:"#show",
            points: [Y.WidgetPositionExt.TL, Y.WidgetPositionExt.BL]
        },
        zIndex:10,
        headerContent: generateHeaderMarkup(),
        bodyContent: "Feed data will be displayed here"
    });

    /* 
     * Add the Standard Module IO Plugin, and configure it to use flash, and a formatter specific
     * to the pipes response we're expecting from the uri request we'll send out.
     */
    overlay.plug({
        fn:StdModIOPlugin, 
        cfg:{
            uri : pipes.baseUri + pipes.feeds["ynews"].uri,
            cfg:{
                xdr: {
                    use:'flash'
                }
            },
            formatter: pipes.formatter
        }
    });
    overlay.render();

    Y.on("change", function(e) {
        var val = this.get("value");
        if (val != -1) {
            overlay.io.set("uri", pipes.baseUri + pipes.feeds[val].uri);
            overlay.io.refresh();
        }
    }, "#feedSelector");

    Y.on("click", function(e) {
        overlay.show();
    }, "#show");

    Y.on("click", function(e) {
        overlay.hide();
    }, "#hide");

});
</script>
	
	<!--END SOURCE CODE FOR EXAMPLE =============================== -->
	
		
		</div>
	</div>			
	</div>
		
	<h3>Creating an IO Plugin For Overlay</h3>

<h4>Setting Up The YUI Instance</h4>

<p>For this example, we'll pull in <code>overlay</code>; the <code>io</code>, <code>json</code> and <code>substitute</code> utility modules and the <code>plugin</code> module. The <code>io</code> module provides the XHR support we need for the IO plugin. The <code>json</code> and <code>substitute</code> modules provide the support we need to parse/transform JSON responses into HTML. The <code>Plugin</code> base class is the class we'll extend to create our io plugin class for <code>Overlay</code>. 
The code to set up our sandbox instance is shown below:</p>

<textarea name="code" class="JScript" rows="1" cols="60">
YUI({...}).use("overlay", "substitute", "io", "json", "plugin", function(Y) {
    // We'll write our code here, after pulling in the default Overlay widget, the IO utility, the Plugin base class along with the Substitute and JSON utilities
}
</textarea>

<p>Using the <code>overlay</code> module will also pull down the default CSS required for overlay, on top of which we only need to add our required look/feel CSS for the example.</p>

<h4>StdModIOPlugin Class Structure</h4>

<p>The <code>StdModIOPlugin</code> class will extend the <code>Plugin</code> base class. Since <code>Plugin</code> derives from <code>Base</code>, we follow the same pattern we use for widgets and other utilities which extend Base to setup our new class.</p>

<p>Namely:</p>

<ul>
    <li>Setting up the constructor to invoke the superclass constructor</li>
    <li>Setting up a <code>NAME</code> property, to identify the class</li>
    <li>Setting up the default attributes, using the <code>ATTRS</code> property</li>
    <li>Providing prototype implementations for anything we want executed during initialization and destruction using the <code>initializer</code> and <code>destructor</code> lifecycle methods</li>
</ul>

<p>Additionally, since this is a plugin, we provide a <code>NS</code> property for the class, which defines the property which will refer to the <code>StdModIOPlugin</code> instance on the host class (e.g. <code>overlay.io</code> will be an instance of <code>StdModIOPlugin</code>)</p>.

<textarea name="code" class="JScript" rows="1" cols="60">
    /* Standard Module IO Plugin Constructor */
    function StdModIOPlugin(config) {
        StdModIOPlugin.superclass.constructor.apply(this, arguments);
    }

    /* 
     * The namespace for the plugin. This will be the property on the widget, which will 
     * reference the plugin instance, when it's plugged in
     */
    StdModIOPlugin.NS = "io";

    /*
     * The NAME of the StdModIOPlugin class. Used to prefix events generated
     * by the plugin class.
     */
    StdModIOPlugin.NAME = "stdModIOPlugin";

    /*
     * The default set of attributes for the StdModIOPlugin class.
     */
    StdModIOPlugin.ATTRS = {
        uri : {...},
        cfg : {...},
        formatter : {...},
        section: {...},
        loading: {...}
    };

    /* Extend the base plugin class */
    Y.extend(StdModIOPlugin, Y.Plugin, {

        // Lifecycle methods.
        initializer: function() {...},

        // IO Plugin specific methods
        refresh : function() {...},

        // Default IO transaction handlers
        _defSuccessHandler : function(id, o) {...},
        _defFailureHandler : function(id, o) {...},
        _defStartHandler : function(id, o) {...},
        _defCompleteHandler : function(id, o) {...},
        _defFormatter : function(val) {...}
    });
</textarea>

<h4>Plugin Attributes</h4>

<p>The <code>StdModIOPlugin</code> is a fairly simple plugin class. It provides incremental functionality. It does not need to modify the behavior of any methods on the host Overlay instance, or monitor any Overlay events (unlike the <a href="overlay-anim-plugin.html">AnimPlugin</a> example).</p>

<p>It sets up the following attributes, which are used to control how the IO plugin's <code>refresh</code> method behaves:</p>

<dl>
    <dt>uri</dt>
    <dd>The uri to use for the io request</dd>
    <dt>cfg</dt>
    <dd>The io configuration object, to pass to io when initiating a transaction</dd>
    <dt>formatter</dt>
    <dd>The formatter to use to formatting response data. The default implementation simply passes back the response data passed in, unchanged.</dd>
    <dt>section</dt>
    <dd>The Standard Module section to which the io plugin instance is bound. Response data will be used to populate this section, after passing through the configured formatter.</dd>
    <dt>loading</dt>
    <dd>The default content to display while an io transaction is in progress</dd>
</dl>

<p>In terms of code, the attributes for the plugin are set up using the standard <code>ATTRS</code> property:</p>

<textarea name="code" class="JScript" rows="1" cols="60">

    StdModIOPlugin.ATTRS = {

        /*
         * The uri to use for the io request
         */
        uri : {
            value:null
        },

        /*
         * The io configuration object, to pass to io when initiating a transaction
         */
        cfg : {
            value:null
        },

        /*
         * The default formatter to use when formatting response data. The default
         * implementation simply passes back the response data passed in. 
         */
        formatter : {
            valueFn: function() {
                return this._defFormatter;
            }
        },

        /*
         * The Standard Module section to which the io plugin instance is bound.
         * Response data will be used to populate this section, after passing through
         * the configured formatter.
         */
        section: {
            value:StdMod.BODY,
            validator: function(val) {
                return (!val || val == StdMod.BODY || val == StdMod.HEADER || val == StdMod.FOOTER);
            }
        },

        /*
         * The default loading indicator to use, when an io transaction is in progress.
         */
        loading: {
            value: '<img class="yui-loading" width="32px" height="32px" src="assets/img/ajax-loader.gif">'
        }
    };
</textarea>

<p>The <code>formatter</code> attribute uses <code>valueFn</code> to define an instance based default value; pointing to the <code>_defFormatter</code> method on the <code>StdModIOPlugin</code> instance.</p>

<h4>Lifecycle Methods: initializer, destructor</h4>

<p>For the purposes of this example, the <code>initializer</code> for the plugin activates the Flash based <a href="../../io/#xdr">XDR</a> transport so that the plugin is able to dispatch both in-domain and cross-domain requests (the transport used for any particular uri is controlled through the plugin's <code>cfg</code> attribute).</p>

<p>The <code>destructor</code> terminates any existing transaction, if active when the plugin is destroyed (unplugged).</p>

<textarea name="code" class="JScript" rows="1" cols="60">
    initializer: function() {
        Y.io.transport({
            id:'flash',
            yid: Y.id,
            src:'../../build/io/IO.swf?stamp=' + (new Date()).getTime()
        });
    }

    /*
     * Destruction code. Terminates the activeIO transaction if it exists
     */
    destructor : function() {
        if (this._activeIO) {
            Y.io.abort(this._activeIO);
            this._activeIO = null;
        }
    },
</textarea>

<h4>The refresh Method</h4>

<p>The <code>refresh</code> method is the main public method which the plugin provides. It's responsible for dispatching the IO request, using the current state of the attributes defined of the plugin. Users will end up invoking the method from the plugin instance attached to the Overlay (<code>overlay.io.refresh()</code>).</p>

<textarea name="code" class="JScript" rows="1" cols="60">
    refresh : function() {
        section = this.get("section");

        if (section && !this._activeIO) {
            var uri = this.get("uri");

            if (uri) {

                cfg = this.get("cfg") || {};
                cfg.on = cfg.on || {};

                cfg.on.start = cfg.on.start || Y.bind(this._defStartHandler, this);
                cfg.on.complete = cfg.on.complete || Y.bind(this._defCompleteHandler, this);

                cfg.on.success = cfg.on.success || Y.bind(this._defSuccessHandler, this);
                cfg.on.failure = cfg.on.failure || Y.bind(this._defFailureHandler, this);

                cfg.method = cfg.method; // io defaults to "GET" if not defined

                Y.io(uri, cfg);
            }
        }
    }
</textarea>

<p>The <code>refresh</code> method, as implemented for the scope of this example, sets up the io configuration object for the transaction it is about to dispatch, filling in the default handlers for io's <code>start</code>, <code>complete</code>, <code>success</code> and <code>failure</code> events, if the user does not provide custom implementations.</p>

<h4>The Default IO Event Handlers</h4>

<p>The default success listener, pulls the response data from the response object, and uses it to update the content in the Overlay section defined by the <code>section</code> attribute. The response data is passed through the <code>formatter</code> configured for the plugin, converting it to the desired output format:</p>

<textarea name="code" class="JScript" rows="1" cols="60">
    _defSuccessHandler : function(id, o) {
        var response = o.responseXML || o.responseText;
        var section = this.get("section");
        var formatter = this.get("formatter");

        // Invoke Overlay method to set content in the currently configured section
        this.get("host").setStdModContent(section, formatter(response));
    }
</textarea>

<p>The default failure listener, displays an error message in the currently configured <code>section</code>, when io communication fails:</p>

<textarea name="code" class="JScript" rows="1" cols="60">
    _defFailureHandler : function(id, o) {
        this.get("host").setStdModContent(this.get("section"), "Failed to retrieve content");
    }
</textarea>

<p>The default start event listener renders the <code>loading</code> content, which remains in place while the transaction is in process, and also stores a reference to the "inprogress" io transaction:</p>

<textarea name="code" class="JScript" rows="1" cols="60">
    _defStartHandler : function(id, o) {
        this._activeIO = o;
        this.get("host").setStdModContent(this.get("section"), this.get("loading"));
    },
</textarea>

<p>The default complete event listener clears out the "inprogress" io transaction object:</p>

<textarea name="code" class="JScript" rows="1" cols="60">
    _defCompleteHandler : function(id, o) {
        this._activeIO = null;
    }
</textarea>

<h4>Using the Plugin</h4>

<p>All objects derived from <a href="../../api/Base.html">Base</a> are <a href="../../api/Plugin.Host.html">Plugin Hosts</a>. They provide <a href="../../api/Plugin.Host.html#method_plug"><code>plug</code></a> and <a href="../../api/Plugin.Host.html#method_unplug"><code>unplug</code></a> methods to allow users to add/remove plugins to/from existing instances. 
They also allow the user to specify the set of plugins to be applied to a new instance, along with their configurations, as part of the constructor arguments.</p>

<p>In this example, we'll create a new instance of an Overlay:</p>

<textarea name="code" class="JScript" rows="1" cols="60">
    /* Create a new Overlay instance, with content generated from script */
    var overlay = new Y.Overlay({
        width:"40em",
        visible:false,
        align: {
            node:"#show",
            points: [Y.WidgetPositionExt.TL, Y.WidgetPositionExt.BL]
        },
        zIndex:10,
        headerContent: generateHeaderMarkup(),
        bodyContent: "Feed data will be displayed here"
    });
</textarea>

<p>And then use the <code>plug</code> method to add the <code>StdModIOPlugin</code>, providing it with a configuration to use when sending out io transactions (The <a href="overlay-anim-plugin.html">Animation Plugin</a> example shows how you could do the same thing during construction):</p>

<textarea name="code" class="JScript" rows="1" cols="60">
    /*
     * Add the Standard Module IO Plugin, and configure it to use flash, and a formatter specific
     * to the pipes response we're expecting from the uri request we'll send out.
     */
    overlay.plug({
        fn:StdModIOPlugin, 
        cfg:{
            uri : pipes.baseUri + pipes.feeds["ynews"].uri,
            cfg:{
                xdr: {
                    use:'flash'
                }
            },
            formatter: pipes.formatter
        }
    });
</textarea>

<p>For this example, the io plugin is configured to use the <code>flash</code> cross-domain transport, to send out requests to the pipes API for the feed the user selects from the dropdown.</p>

<h4>Getting Feed Data Through Pipes</h4>

<p>We setup an object (<code>pipes</code>) to hold the feed URIs, which can be looked up and passed to the plugin to dispatch requests for new data:</p>

<textarea name="code" class="JScript" rows="1" cols="60">

/* The Pipes feed URIs to be used to dispatch io transactions */

var pipes = {
    baseUri : 'http:/'+'/pipes.yahooapis.com/pipes/pipe.run?_id=6b7b2c6a32f5a12e7259c36967052387&_render=json&url=http:/'+'/',
    feeds : {
        ynews : {
            title: 'Yahoo! US News',
            uri: 'rss.news.yahoo.com/rss/us'
        },
        yui : {
            title: 'YUI Blog',
            uri: 'feeds.yuiblog.com/YahooUserInterfaceBlog'
        },
        slashdot : {
            title: 'Slashdot',
            uri: 'rss.slashdot.org/Slashdot/slashdot'
        },
        ...
    },

    ...
</textarea>

<p>The data structure also holds the default formatter (<code>pipes.formatter</code>) required to convert the JSON responses from the above URIs to HTML. The JSON utility is first used to parse the json response string. The resulting object is iterated around, using Y.each, and substitute is used to generate the list markup:</p>

<textarea name="code" class="JScript" rows="1" cols="60">
    ...

    // The default formatter, responsible for converting the JSON responses received,
    // into HTML. JSON is used for the parsing step, and substitute for some basic 
    // templating functionality

    formatter : function (val) {
        var formatted = "Error parsing feed data";
        try {
            var json = Y.JSON.parse(val);
            if (json && json.count) {
                var html = ['<ul class="yui-feed-data">'];
                var linkTemplate = '<li><a href="{link}" target="_blank">{title}</a></li>';

                // Loop around all the items returned, and feed them into the template above,
                // using substitute.
                Y.each(json.value.items, function(v, i) {
                    if (i < 10) {
                        html.push(Y.substitute(linkTemplate, v));
                    }
                });
                html.push("</ul>");
                formatted = html.join("");
            } else {
                formatted = "No Data Available";
            }
        } catch(e) {
            formatted = "Error parsing feed data";
        }
        return formatted;
    }
</textarea>

<p>The <code>change</code> handler for the select dropdown binds everything together, taking the currently selected feed, constructing the URI for the feed, setting it on the plugin, and sending out the request:</p>

<textarea name="code" class="JScript" rows="1" cols="60">
    /* Handle select change */
    Y.on("change", function(e) {
        var val = this.get("value");
        if (val != -1) {
            // Set the new URI value on the io plugin
            overlay.io.set("uri", pipes.baseUri + pipes.feeds[val].uri);

            // Send out a request to refresh the current section's contents
            overlay.io.refresh();
        }
    }, "#feedSelector");
</textarea>
				</div>
				<div class="yui-u sidebar">
					
				
					<div id="examples" class="mod box4">
                        <div class="hd">
						<h4>
    Overlay Examples:</h4>
                        </div>
						<div class="bd">
							<ul>
								<li><a href='../overlay/overlay-xy.html'>Basic XY Positioning</a></li><li><a href='../overlay/overlay-align.html'>Extended XY Positioning</a></li><li><a href='../overlay/overlay-stack.html'>Stack Support</a></li><li><a href='../overlay/overlay-stdmod.html'>Standard Module Support</a></li><li class='selected'><a href='../overlay/overlay-io-plugin.html'>IO Plugin</a></li><li><a href='../overlay/overlay-anim-plugin.html'>Animation Plugin</a></li><li><a href='../node-focusmanager/node-focusmanager-3.html'>Accessible Menu Button (included with examples for Focus Manager Node Plugin)</a></li>							</ul>
						</div>
					</div>
					
					<div class="mod box4">
                        <div class="hd">
						<h4>More Overlay Resources:</h4>
                        </div>
                        <div class="bd">
						<ul>
							<!-- <li><a href="http://developer.yahoo.com/yui/overlay/">User's Guide</a> (external)</li> -->
						<li><a href="../../api/module_overlay.html">API Documentation</a></li>
</ul>
                        </div>
					</div>
			  </div>
		</div>
		
		</div>
	</div>


<div class="yui-b toc3" id="tocWrapper">
<!-- TABLE OF CONTENTS -->
<div id="toc">
	
<ul>
<li class="sect first">YUI 3.x Project</li><li class="item"><a title="The Yahoo! User Interface (YUI) Library, 3.x Branch, " href="http://developer.yahoo.com/yui/3/">YUI 3 Web Site (external)</a></li><li class="item"><a title="Examples of every YUI utility and control in action" href="../../examples/">YUI 3 Examples</a></li><li class="item"><a title="Instantly searchable API documentation for the entire YUI library." href="../../api/">YUI 3 API Docs</a></li><li class="item"><a title="The YUI Library can be downloaded from SourceForge" href="http://sourceforge.net/projects/yui/">YUI 3 on Sourceforge (external)</a></li><li class="item"><a title="YUI is free and open, offered under a BSD license." href="http://developer.yahoo.com/yui/3/license.html">YUI License (external)</a></li><li class="sect">YUI 3 Core - Examples</li><li class="item"><a title="YUI (Global Prerequisite) - Functional Examples" href="../../examples/yui/index.html">YUI (Global Prerequisite)</a></li><li class="item"><a title="Event - Functional Examples" href="../../examples/event/index.html">Event</a></li><li class="item"><a title="Node - Functional Examples" href="../../examples/node/index.html">Node</a></li><li class="sect">YUI 3 Component Infrastructure - Examples</li><li class="item"><a title="Attribute - Functional Examples" href="../../examples/attribute/index.html">Attribute</a></li><li class="item"><a title="Plugin - Functional Examples" href="../../examples/plugin/index.html">Plugin</a></li><li class="item"><a title="Widget - Functional Examples" href="../../examples/widget/index.html">Widget</a></li><li class="sect">YUI 3 Utilities - Examples</li><li class="item"><a title="Animation - Functional Examples" href="../../examples/anim/index.html">Animation</a></li><li class="item"><a title="Cache - Functional Examples" href="../../examples/cache/index.html">Cache</a></li><li class="item"><a title="Cookie - Functional Examples" href="../../examples/cookie/index.html">Cookie</a></li><li class="item"><a title="DataSchema - Functional Examples" href="../../examples/dataschema/index.html">DataSchema</a></li><li class="item"><a title="DataSource - Functional Examples" href="../../examples/datasource/index.html">DataSource</a></li><li class="item"><a title="DataType - Functional Examples" href="../../examples/datatype/index.html">DataType</a></li><li class="item"><a title="Drag &amp; Drop - Functional Examples" href="../../examples/dd/index.html">Drag &amp; Drop</a></li><li class="item"><a title="Get - Functional Examples" href="../../examples/get/index.html">Get</a></li><li class="item"><a title="History - Functional Examples" href="../../examples/history/index.html">History</a></li><li class="item"><a title="ImageLoader - Functional Examples" href="../../examples/imageloader/index.html">ImageLoader</a></li><li class="item"><a title="IO - Functional Examples" href="../../examples/io/index.html">IO</a></li><li class="item"><a title="JSON (JavaScript Object Notation) - Functional Examples" href="../../examples/json/index.html">JSON</a></li><li class="item"><a title="Queue - Functional Examples" href="../../examples/queue/index.html">Queue</a></li><li class="item"><a title="Stylesheet - Functional Examples" href="../../examples/stylesheet/index.html">Stylesheet</a></li><li class="sect">YUI 3 Widgets - Examples</li><li class="selected "><a title="Overlay - Functional Examples" href="../../examples/overlay/index.html">Overlay</a></li><li class="item"><a title="Slider - Functional Examples" href="../../examples/slider/index.html">Slider</a></li><li class="sect">YUI 3 Node Plugins - Examples</li><li class="item"><a title="FocusManager Node Plugin - Functional Examples" href="../../examples/node-focusmanager/index.html">FocusManager Node Plugin</a></li><li class="item"><a title="MenuNav Node Plugin - Functional Examples" href="../../examples/node-menunav/index.html">MenuNav Node Plugin</a></li><li class="sect">YUI 3 CSS - Examples</li><li class="item"><a title="YUI CSS Reset - Functional Examples" href="../../examples/cssreset/index.html">CSS Reset</a></li><li class="item"><a title="YUI Fonts - Functional Examples" href="../../examples/cssfonts/index.html">CSS Fonts</a></li><li class="item"><a title="YUI Base - Functional Examples" href="../../examples/cssbase/index.html">CSS Base</a></li><li class="sect">YUI 3 Developer Tools - Examples</li><li class="item"><a title="Console - Functional Examples" href="../../examples/console/index.html">Console</a></li><li class="item"><a title="Profiler - Functional Examples" href="../../examples/profiler/index.html">Profiler</a></li><li class="item"><a title="Test - Functional Examples" href="../../examples/test/index.html">Test</a></li><li class="sect">The YUI Community</li><li class="item"><a title="The Yahoo! User Interface Blog" href="http://yuiblog.com">YUI Blog (external)</a></li><li class="item"><a title="The Yahoo! Group YDN-JavaScript hosts the YUI community forum" href="http://tech.groups.yahoo.com/group/ydn-javascript/">YUI Forum (external)</a></li><li class="item"><a title="The Yahoo! Group yui3 is dedicated to the 3.x branch of the Yahoo! User Interface (YUI) Library." href="http://tech.groups.yahoo.com/group/yui3/">YUI 3 Forum (external)</a></li><li class="item"><a title="YUI is used by Yahoo! and by hundreds of other sites, including many you know and love." href="/yui/poweredby/">YUI Sightings (external)</a></li><li class="item"><a title="Videos and podcasts from the YUI Team and from the Yahoo! frontend engineering community." href="http://developer.yahoo.com/yui/theater/">YUI Theater (external)</a></li><li class="sect">YUI Articles on the YUI Website</li><li class="item"><a title="Answers to Frequently Asked Questions about the YUI Library" href="http://developer.yahoo.com/yui/articles/faq/">YUI FAQ (external)</a></li><li class="item"><a title="Yahoo!'s philosophy of Graded Browser Support" href="http://developer.yahoo.com/yui/articles/gbs/">Graded Browser Support (external)</a></li><li class="item"><a title="Reporting Bugs and Making Feature Requests for YUI Components" href="http://developer.yahoo.com/yui/articles/reportingbugs/">Bug Reports/Feature Requests (external)</a></li><li class="item"><a title="Serve YUI source files from Yahoo! -- free, fast, and simple" href="http://developer.yahoo.com/yui/3/articles/hosting/">Serving YUI Files from Yahoo! (external)</a></li></ul>
</div>
</div>
	</div><!--closes bd-->

	<div id="ft">
        <p class="first">Copyright &copy; 2009 Yahoo! Inc. All rights reserved.</p>
        <p><a href="http://privacy.yahoo.com/privacy/us/devel/index.html">Privacy Policy</a> - 
            <a href="http://docs.yahoo.com/info/terms/">Terms of Service</a> - 
            <a href="http://docs.yahoo.com/info/copyright/copyright.html">Copyright Policy</a> - 
            <a href="http://careers.yahoo.com/">Job Openings</a></p>
	</div>
</div>
<script src="../../assets/dpSyntaxHighlighter.js"></script>
<script language="javascript"> 
dp.SyntaxHighlighter.HighlightAll('code'); 
</script>
</body>
</html>
